<?php
include 'lib/controllerWithoutGetOrPost.php';
include 'lib/LoggedIn.php';
$loggedIn = new LoggedIn();
$loggedIn->setPermission = "Admin Area";
if(!$loggedIn->check()) {
    echo $loggedIn->message();
} else {

include("header2.php");

$query = "Select Charity.`ID`, Charity.`Name`, `Email`, `Web`, `DonateDirect`, `ShowCharity`, `ContactFirstName`, `ContactLastName`, `Suburb`, `Address1`, `Address2`, `Telephone`, `TelephoneDD`, `Fax`, `Blurb`, Country.`Name` as `CountryName`, CityTown.`Name` as CityTownName from Charity left join Country on Charity.CountryID = Country.ID left join CityTown on CityTown.ID = Charity.CityTownID order by Charity.Name ASC";

// Perform Query
$result = mysql_query($query, $link);

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
echo "<table style=\"width:4000px\"><thead><tr><th>ID</th><th>Name</th><th>Email</th><th>Web</th><th>Donate Direct</th><th>Show Charity</th><th>Country</th><th>First Name</th><th>Last Name</th><th>Suburb</th><th>Address 1</th><th>Address 2</th><th>Telephone</th><th>Telephone DD</th><th>City/Town</th><th>Fax</th><th style=\"width:300px\">Blurb</th></tr></thead>";
while ($row = mysql_fetch_assoc($result)) {

	echo "<tr><td style=\"width:150px;\"><a rel=\"external\" href=\"editcharity.php?id=".$row['ID']."\">Edit ID: ".$row['ID']."</a></td>";
	echo "<td style=\"width:600px\">".$row['Name']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Email']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Web']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['DonateDirect']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['ShowCharity']."</td>";
	echo "<td style=\"width:150px;\">".$row['CountryName']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['ContactFirstName']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['ContactLastName']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Suburb']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Address 1']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Address 2']."</td>";
  echo "<td style=\"overflow:hidden\">".$row['Telephone']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['TelephoneDD']."</td>";
	echo "<td style=\"width:150px;\">".$row['CityTownName']."</td>";
	echo "<td style=\"overflow:hidden\">".$row['Fax']."</td>";
	echo "<td style=\"width:2500px;\">".$row['Blurb']."</td>";
	echo "</tr>";
   
}
echo "</table></body></html>";

// Free the resources associated with the result set
// This is done automatically at the end of the script
mysql_free_result($result);
mysql_close($link);

}
?>
